//
// a Client to request Date/Time from server
// connection: L2CAP
// usage: you can use l2ping to check if the connection is up and running.
//

import java.io.*;
import javax.bluetooth.*;
import javax.microedition.io.*;

public class DateClient {
	public static void main(String args[]) throws BluetoothStateException {
		LocalDevice localdev = null;
		L2Listener listener = new L2Listener();

		try {
			localdev = LocalDevice.getLocalDevice();
		} catch (BluetoothStateException e) {
			System.out.println("ERROR: cannot access local device");
			System.exit(1);
		}

		DiscoveryAgent agent = localdev.getDiscoveryAgent();
		try {
			// startInquiry() is non-blocking.
			agent.startInquiry(DiscoveryAgent.GIAC, listener);
		} catch (BluetoothStateException e) {
			System.out.println("ERROR: device inquiry failed");
			System.exit(2);
		}

		// pause for a while
		while (listener.getDevFound() == null)
			try {
				Thread.sleep(5000);
			} catch (Exception e) {
			}
		RemoteDevice rd = listener.getDevFound();

		UUID[] uuidSet = new UUID[1];
		uuidSet[0] = new UUID("102030405060708090A0B0C0D0E0F011", false);

		int trans;
		try {
			trans = agent.searchServices(null, uuidSet, rd, listener);
		} catch (BluetoothStateException e) {
			System.out.println("device unable to begin service inquiry");
		}
	}
}
